package com.dt.common.validation.parser;

import java.lang.reflect.Field;

import com.alibaba.fastjson.JSONObject;
import com.dt.common.validation.exception.BuildingException;
import com.dt.common.validation.impl.DefaultValidationDefinition;
import com.dt.common.validation.itf.PropertyGetter;

public abstract class DefinitionParser {

	public abstract DefaultValidationDefinition parseFromAnnotation(Field field, PropertyGetter propertyGetter);

	public abstract DefaultValidationDefinition parseFromJson(JSONObject metaValues);

	protected String getMsgDefinition(JSONObject metaValues, boolean mustDef) {
		String msg = metaValues.getString("msg");
		if (mustDef && (msg == null || msg.isEmpty())) {
			throw new BuildingException("msg must defined.");
		}
		return msg;
	}

}
